package gdut.imis.controller;

import gdut.imis.Utils.Result;
import gdut.imis.service.CourseService;
import gdut.imis.vo.CourseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author JiaFu
 * @Date 2023/4/7 18:12
 */
@RestController
@RequestMapping("/course")
@Api(value = "课程档案接口", tags = {"课程档案接口"})
@RequiredArgsConstructor
public class CourseController extends BaseController {
    private final CourseService courseService;

    @ApiOperation("新增课程档案(拥有course权限)")
    @PostMapping("/addCourse")
    @PreAuthorize("@cp.hasPermission('course')")
    public Result addCourse(@RequestBody CourseVo courseVo) {
        return courseService.addCourse(courseVo);
    }


    @ApiOperation("根据学生id查询学生上的第一节课的信息")
    @GetMapping("/getStudentFirstCourse/{studentId}")
    public Result getStudentFirstCourse(@PathVariable("studentId") Long studentId) {
        return courseService.getStudentFirstCourse(studentId);
    }

    @ApiOperation("根据学生id分页查询学生拥有的课程")
    @GetMapping("/getPageCoursesByStuId/{studentId}/{pageNo}/{pageSize}")
    public Result getPageCoursesByStuId(
            @PathVariable("studentId") Long studentId,
            @PathVariable("pageNo") Integer pageNo,
            @PathVariable("pageSize") Integer pageSize) {
        Result result = this.checkPageParams(pageNo, pageSize);
        if (result.getCode() == 0){
            return courseService.getPageCoursesByStuId(studentId,pageNo,pageSize);
        }
        return result;
    }
}
